package deformedGrid;

import grid.QGridGenerator;
import grid.GridPoint;


/**
 * 
 * An subclass of the GridDeformation, that generates a rectangular grid
 *
 */
public class RectangelGridDeformation extends GridDeformation {


	public final int numGridPointsX;
	public final int numGridPointsY;
	public final int width;
	public final int height;
	/**
	 * the base point is (0,0)
	 * @param numGridPointsX how many columns the grid has
	 * @param numGridPointsY how many rows the grid has
	 * @param width width of the grid
	 * @param height height of the grid
	 */
	public RectangelGridDeformation(int numGridPointsX, int numGridPointsY,
			int width, int height) {
		super(QGridGenerator.generateUngluedQGrid(numGridPointsX,numGridPointsY, width, height));
		this.numGridPointsX =numGridPointsX;
		this.numGridPointsY = numGridPointsY;
		this.width = width;
		this.height = height;
		
	}
	
	
	public GridPoint getOriginalGridPoint(int x, int y) {
		return this.getOriginalGrid().get(x + numGridPointsX * y);
	}
	
	
	public GridPoint getGridPoint(int x, int y) {
		return this.getGrid().get(x + numGridPointsX * y);
	}

	/**
	 * 
	 * @param x
	 * @param y
	 * @return x+sizeXCoords*y or -1 if out of bounds
	 * 
	 */
	public int getGridPointIndex(int x, int y) {
		int index = x + numGridPointsX * y;
		if (x >= 0 && x < numGridPointsX && y >= 0 && y < numGridPointsY) {
			return index;
		}
		return -1;
	}
	
	

}
